package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.Product;
import com.ruoyi.system.domain.vo.ProductVo;
import com.ruoyi.system.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/product")
public class ProductController extends BaseController {

    @Autowired
    private ProductService productService;

    @PostMapping("/create")
    public AjaxResult createProduct(@RequestBody Product product){
        return toAjax(productService.createProduct(product));
    }

    @PostMapping("/removeStatus")
    public AjaxResult removeStatusProduct(@RequestBody Product product){
        return toAjax(productService.deleteProduct(product));
    }

    @PostMapping("/update")
    public AjaxResult updateProduct(@RequestBody Product product){
        return toAjax(productService.updateProduct(product));
    }

    @PostMapping("/shelf")
    public AjaxResult shelfProduct(Product product){
        return toAjax(productService.shelfProduct(product));
    }

    @GetMapping("/search")
    public TableDataInfo searchProduct(Product product){
        startPage();
        List<Product> search = productService.search(product);
        return getDataTable(search);
    }

    @GetMapping("/list")
    public TableDataInfo getProductList(Product product){
        startPage();
        List<Product> productList = productService.getProductList(product);
        return getDataTable(productList);
    }

    @GetMapping("/getProduct/{id}")
    public AjaxResult getProductId(@PathVariable Integer id){
        AjaxResult ajax = AjaxResult.success();
        Product productId = productService.getProductId(id);
        ajax.put(AjaxResult.DATA_TAG,productId);
        return ajax;
    }

    @GetMapping("/listProduct")
    public TableDataInfo getProductVo(ProductVo productVo){
        startPage();
        List<ProductVo> product = productService.getProduct(productVo);
        return getDataTable(product);
    }
}
